<template>
    <div class="update-container">
      <h1 v-if="!downloaded">发现新版本: {{ newVersion }}</h1>
      <div v-if="downloading">
        <p>下载进度: {{ progress }}%</p>
        <el-progress :percentage="progress" :stroke-width="20" />
      </div>
      
      <div v-if="downloaded" class="update-ready">
        <h2>🎉 更新已下载完成!</h2>
        <p>新版本已准备就绪，点击安装后应用将重启</p>
        <el-button type="primary" size="large" @click="installUpdate">
          立即安装
        </el-button>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref, onMounted } from 'vue';
  import { ipcRenderer } from 'electron';
  
  const progress = ref(0);
  const downloaded = ref(false);
  const downloading = ref(false);
  const newVersion = ref('');
  
  onMounted(() => {
    ipcRenderer.on('download_progress', (_, p) => {
      downloading.value = true;
      progress.value = Math.floor(p.percent);
    });
    
    ipcRenderer.on('update_downloaded', () => {
      downloaded.value = true;
      downloading.value = false;
    });
  });
  
  const installUpdate = () => {
    ipcRenderer.send('install_update');
  };
  </script>
  
  <style scoped lang="scss">
  .update-container {
    padding: 40px;
    text-align: center;
    
    .update-ready {
      margin-top: 30px;
      
      h2 {
        color: #67C23A;
        margin-bottom: 15px;
      }
      
      .el-button {
        margin-top: 20px;
        padding: 15px 40px;
        font-size: 16px;
      }
    }
  }
  </style>